package org.openlvb.openlvp.calendar;

import java.util.Date;
import java.util.GregorianCalendar;

import com.vaadin.addon.calendar.ui.Calendar;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.Button;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

public class CalendarMenuPanel extends VerticalLayout implements Property.ValueChangeListener{
	
	private InlineDateField inLineDateField;
	private CalendarPanel calendarPanel;

	public CalendarMenuPanel(CalendarPanel calendarPanel) {
		this.calendarPanel = calendarPanel;
		inLineDateField = new InlineDateField();
		inLineDateField.setValue(new Date());
		inLineDateField.setResolution(InlineDateField.RESOLUTION_DAY);
		inLineDateField.setImmediate(true);
		inLineDateField.addListener(this);
		addComponent(inLineDateField);
		Button btAddShare = new Button("Partager mon calendrier");
		addComponent(btAddShare);
		VerticalLayout layout = new VerticalLayout();
	    layout.setWidth("90%");
	    layout.setHeight("90%");
	    layout.setSpacing(true);
	    layout.addStyleName("border");
	    layout.setMargin(true);
	    
	    TaskPanel taskPanel = new TaskPanel("Tâche 1", "", "", TaskPanel.CATEGORY_ORANGE);
	    TaskPanel taskPanel2 = new TaskPanel("Tâche 2", "", "", TaskPanel.CATEGORY_GREY);
	    layout.addComponent(taskPanel);
	    layout.addComponent(taskPanel2);
	    addComponent(layout);
		}

	public void valueChange(ValueChangeEvent event) {
		Date date = (Date) event.getProperty().getValue();
		Calendar cal = calendarPanel.getMainCalendarPanel().getCalendar();
		cal.setStartDate(cal.getFirstDateForWeek(date));
		cal.setEndDate(cal.getLastDateForWeek(date));
	}

}
